const express = require("express");
const app = express();
const router = new express.Router();
const bodyParser = require("body-parser");
const db = require("../db/index")
const Users = require("../models/usersSchema");
router.use(bodyParser.urlencoded({ extended: true }));
router.post("/res", async (req, res) => {
    await db;
    const user = req.body;
    const result = await Users.create(user);
    console.log(result);
    res.send("注册成功");
})
router.post("/login", async (req, res) => {
    await db;
    const { username, password } = req.body;
    const result = await Users.find({ username });
    console.log(result);
    const arr = [];
    result.forEach(item => {
        arr.push(item.username)
        arr.push(item.password)
    })
    if (req.body.username == arr[0] && req.body.password == arr[1]) {
        res.send("登录成功")
    } else {
        res.send("登录失败")
    }
})
module.exports = router;